package com.tsd.system.controller;

import com.tsd.core.vo.ErrorCode;
import com.tsd.core.vo.HttpResult;
import com.tsd.core.vo.PageBean;
import com.tsd.system.entity.SysLogInfo;
import com.tsd.system.service.SysLogInfoService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 描述：SysLogInfo 控制层
 *
 * @author Hillpool
 * @date 2019/07/31 14:22:11
 */
@Controller
@Scope("prototype")
@RequestMapping("/api/v2")
public class SysLogInfoController extends SystemBaseController {

    @Autowired
    private SysLogInfoService sysLogInfoService;

    @ApiOperation(value = "根据id获取SysLogInfo")
    @ResponseBody
    @RequestMapping(value = "/getSysLogInfoById.action", method = RequestMethod.POST)
    public HttpResult<SysLogInfo> getSysLogInfoById() {
        HttpResult<SysLogInfo> hr = new HttpResult<SysLogInfo>();
        try {
            Map<String, Object> map = super.getParams(request);
            Long id = (Long) map.get("id");
            super.checkEmpty(id, "请提供参数id");
            SysLogInfo sysLogInfo = sysLogInfoService.queryByPrimaryKey(id);
            hr.setData(sysLogInfo);
            hr.setCode(ErrorCode.CODE_SUCCESS);
        } catch (Exception e) {
            super.procException(hr, e);
        }
        return hr;
    }

    @ApiOperation(value = "根据id删除SysLogInfo")
    @ResponseBody
    @RequestMapping(value = "/deleteSysLogInfo.action", method = RequestMethod.POST)
    public HttpResult<String> deleteSysLogInfo() {
        HttpResult<String> hr = new HttpResult<String>();
        try {
            Map<String, Object> map = super.getParams(request);
            Long id = (Long) map.get("id");
            super.checkEmpty(id, "请提供参数id");
            sysLogInfoService.deleteByPrimaryKey(id);
            hr.setCode(ErrorCode.CODE_SUCCESS);
        } catch (Exception e) {
            super.procException(hr, e);
        }
        return hr;
    }

    @ApiOperation(value = "分页查询SysLogInfo")
    @ResponseBody
    @RequestMapping(value = "/findSysLogInfos.action", method = RequestMethod.POST)
    public HttpResult<List<SysLogInfo>> findSysLogInfos() {
        HttpResult<List<SysLogInfo>> hr = new HttpResult<List<SysLogInfo>>();
        try {
            Map<String, Object> map = super.getParams(request);
            Map<String, Object> params = new HashMap<String, Object>();
            //String searchValue = (String) map.get("searchValue");
            //if (!HlpUtils.isEmpty(searchValue)) {
            //	params.put("searchValue", "%" + searchValue + "%");
            //}
            PageBean page = new PageBean(map);
            List<SysLogInfo> list = sysLogInfoService.findSysLogInfos(params, page);
            hr.setData(list);
            hr.setPage(page);
            hr.setCode(ErrorCode.CODE_SUCCESS);
        } catch (Exception e) {
            super.procException(hr, e);
        }
        return hr;
    }

}
